package fi.iki.joker.mobilogger.blogs;

import android.util.Log;
import fi.iki.joker.mobilogger.blogs.BlogConfigConstants.BlogInterfaceType;

/**
 * Serves singleton instances of blog interfaces to callers.
 * Again, may be an overgeneralization for a mobile app but originally I would like to keep the
 * coupling as loose as possible. 
 * @author juhak
 *
 */

public class BlogInterfaceFactory {

	private static final String TAG = "BlogInterfaceFactory";
	
	static BlogInterface instance;
	
	public static BlogInterface getInstance(BlogInterfaceType type) {
		if(type == BlogConfigConstants.BlogInterfaceType.BLOGGER_DEBUG) {
			if(instance == null || !(instance instanceof GoogleBloggerHttpsApi)) {
				instance = new GoogleBloggerHttpsApi();
			}
			return instance;
		} else if(type == BlogConfigConstants.BlogInterfaceType.ATOM) {
			if(instance == null || !(instance instanceof AtomCompliantAPI)) {
				instance = new AtomCompliantAPI();
			}
			return instance;
		} else if(type == BlogConfigConstants.BlogInterfaceType.RSS) {
			if(instance == null || !(instance instanceof RSSCompliantAPI)) {
				instance = new RSSCompliantAPI();
			}
			return instance;
		} else if(type == BlogConfigConstants.BlogInterfaceType.BLOGGER) {
			if(instance == null || !(instance instanceof GoogleBloggerAPI)) {
				instance = new GoogleBloggerAPI();
			}
			return instance;
		} else if(type == BlogConfigConstants.BlogInterfaceType.METAWEBLOG) {
			if(instance == null || !(instance instanceof  MetaWeblogCompliantAPI)) {
				instance = new MetaWeblogCompliantAPI();
			}
			return instance;
		} else if(type == BlogConfigConstants.BlogInterfaceType.LIVEJOURNAL) {
			if(instance == null || !(instance instanceof LiveJournalAPI)) {
				instance = new LiveJournalAPI();
			}
			return instance;
		} else {
			Log.e(TAG,"Tried to instantiate an unsupported BlogInterface type!");
			return null;
		}
	}
	
}
